<template>
  <div>
    <el-carousel :interval="6000" arrow="always" height="500px">
      <el-carousel-item v-for="(item, index) in carouselImages" :key="index">
        <img :src="item" alt="电影图片" class="carousel-image" @click="showVideo(index)" />
      </el-carousel-item>
    </el-carousel>

    <div v-if="isVideoVisible" class="video-overlay" @click.self="hideVideo">
      <div class="video-container">
        <video :src="videoUrl" controls autoplay class="video-player"></video>
        <button class="close-btn" @click="hideVideo">关闭</button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 引入本地图片资源
      carouselImages: [
        require('@/assets/电影1.jpg'),
        require('@/assets/电影2.jpg'),
        require('@/assets/电影3.jpg')
      ],
      // 视频路径数组，与图片一一对应
      videoUrls: [
        require('@/assets/sp1.mp4'),
        require('@/assets/sp2.mp4'),
        require('@/assets/sp3.mp4')
      ],
      isVideoVisible: false,
      videoUrl: null
    };
  },
  methods: {
    showVideo(index) {
      this.videoUrl = this.videoUrls[index]; // 根据 index 获取对应的视频
      this.isVideoVisible = true;
    },
    hideVideo() {
      this.isVideoVisible = false;
      this.videoUrl = null; // 停止视频播放
    }
  }
};
</script>

<style>
.carousel-image {
  width: 100%;
  height: 500px;
  object-fit: cover;
  /* 图片自适应容器 */
}

/* 视频遮罩层 */
.video-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

/* 视频容器 */
.video-container {
  position: relative;
  max-width: 75%;
  max-height: 75%;
}

/* 视频播放器样式 */
.video-player {
  width: 100%;
  height: auto;
  border-radius: 8px;
}

/* 关闭按钮 */
.close-btn {
  margin-top: 10px;
  padding: 10px 20px;
  font-size: 16px;
  color: white;
  background-color: #ff4d4f;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}
</style>